﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Main.Master" Inherits="System.Web.Mvc.ViewPage<Defect_Tracking_System.Models.DefectDetailsModel>" %>

<asp:Content ID="TitleContent" ContentPlaceHolderID="TitleContent" runat="server">
	Details
</asp:Content>

<asp:Content ID="MainContent" ContentPlaceHolderID="MainContent" runat="server">
<style type="text/css" rel="Stylesheet">
    div.contentLeft
    {
        font-size: 13px;
        margin-top: 5px;
        padding: 5px;
        width: 45%;
        float: left;
    }
    div.contentRight
    {
        font-size: 13px;
        margin-top: 5px;
        padding: 5px;
        width: 45%;
        float:right;
    }
    div.content
    {
        font-size: 13px;
        margin-top: 5px;
        padding: 5px;
        width: 98%;
        float: left;
        margin-left: auto;
        margin-right:auto;
    }
    a.link
    {
        color: Blue;
    }
    a:hover.link
    {
        text-decoration: underline;
    }
    p
    {
        margin-top: 20px;   
    }
</style>
<!--  start page-heading -->
	<div id="page-heading">
		<h1>Defect Details</h1>
	</div>
	<!-- end page-heading -->

	<table border="0" width="100%" cellpadding="0" cellspacing="0" id="content-table">
	<tr>
		<th rowspan="3" class="sized"><img src="/Content/images/shared/side_shadowleft.jpg" width="20" height="300" alt="" /></th>
		<th class="topleft"></th>
		<td id="tbl-border-top">&nbsp;</td>
		<th class="topright"></th>
		<th rowspan="3" class="sized"><img src="/Content/images/shared/side_shadowright.jpg" width="20" height="300" alt="" /></th>
	</tr>
	<tr>
		<td id="tbl-border-left"></td>
		<td>
		<!--  start content-table-inner ...................................................................... START -->
        <div id="tabs">
        <ul>
            <li><a href="#content-table-inner">Details</a></li>
            <li><a href="#Resolution">Resolution</a></li>
            <li><a href="#Attachment">Attachment</a></li>
            <li><a href="#History">History</a></li>
        </ul>
		<div id="content-table-inner">
			<!--  start table-content  -->
			<div id="table-content">
                <div class="content" width="100%" align="center">Defect Number: <%: Model.Defect.DefectNumber %> - Created by: <%: Model.Defect.AccountCreator.UserName%> at <%: String.Format("{0:g}", Model.Defect.CreatedDate)%></div>
                <div class="contentLeft">Defect Title: <strong><%: Model.Defect.DefectTitle%></strong></div>
                <div class="contentRight">Type: <strong><%: Model.Defect.Type%></strong></div>
                <div class="contentLeft">Project: <strong><%: Model.Defect.Project.ProjectName%></strong></div>
                <div class="contentRight">Version: <strong><%: Model.Defect.Version%></strong></div>
                <div class="contentLeft">Originator: <strong><%: Model.Defect.Client.FirstName%> <%: Model.Defect.Client.LastName%> - <%: Model.Defect.Client.Company%></strong></div>
                <div class="contentRight">Priority: <strong><%: Model.Defect.Priority%></strong></div>
                <div class="contentLeft">Assigned To: <strong>
                <% if (Model.Defect.AssignedMember != null)
                   {%>
                       <%: Model.Defect.AccountAssignedMember.UserName%>
                   <% } %>
                    </strong>
                </div>
                <div class="contentRight">Status: <strong><%: Model.Defect.Status%></strong></div> 
                <div class="content">Diagnosis: <%: Model.Defect.Diagnosis%></div>
                <div class="content"><fieldset><legend>Description</legend><div style="margin: 15px 10px"><%= Model.Defect.Description%></div></fieldset></div>
                <div align="right" class="content" style="width: 95%">
                <% if (!User.IsInRole("User") || (User.IsInRole("User") && Model.Defect.AccountCreator.UserName == User.Identity.Name) || (User.IsInRole("User") && Model.Defect.AssignedMember != null && Model.Defect.AccountAssignedMember.UserName == User.Identity.Name))
                   {
                       if (Model.Defect.IsClosed)
                       {%>
                        <a class="link" href="/Defect/CloseReopenDefect?id=<%: Model.Defect.DefectId %>&act=ReOpen&requesturl=<%: Request.Url.ToString() %>" title="Re-open this defect">Re-Open</a> | 
                     <%}
                       else
                       {%>
                        <a class="link" href="/Defect/CloseReopenDefect?id=<%: Model.Defect.DefectId %>&act=Close&requesturl=<%: Request.Url.ToString() %>" title="Close this defect">Close</a> | 
                     <%}
                    } %>
                <% if (!User.IsInRole("User") || User.Identity.Name == Model.Defect.AccountCreator.UserName || (Model.Defect.AssignedMember != null && Model.Defect.AccountAssignedMember.UserName == User.Identity.Name))
                   { %>
                        <a class="link" href="/Defect/Edit/<%: Model.Defect.DefectId %>?ReturnUrl=<%= Request.Url.ToString() %>" title="Edit">Edit</a> | 
                <% } %>
                <% if (User.IsInRole("Project Admin") || User.IsInRole("Group Admin") || User.Identity.Name == Model.Defect.AccountCreator.UserName)
                   { %>
                        <a class="link" href="/Defect/DeleteDefect/<%: Model.Defect.DefectId %>/1/All" title="Delete" onclick="return confirm('Are you sure to delete this defect?')">Delete</a> | 
                <% } %>
              <a class="link" href="/Defect/Index" title="Back">Back to list</a>
            </div>
		    </div>
			<!--  end content-table  -->
			<div class="clear"></div>
            <fieldset style="width: 90%; margin-left: auto; margin-right: auto; padding-left: 15px">
            <legend>Comments</legend>
            <br /><br />
		    <% foreach (var item in Model.Comments.ToList())
               { %>
                    <div style="margin: 15px"><%= item.Content %> <span style="font-size: 10px; color: gray">(By <%: item.Account.UserName %> at <%: String.Format("{0:g}", item.CreatedDate) %>)</span></div>
            <% } %>
            <br /><br />
            <% if(Model.Defect.Project.IsActive){ %>
            <form action="/Defect/CommentOnDefect" method="post" name="formMain">
                <input type="hidden" name="DefectId" value="<%: Model.Defect.DefectId %>" />
                <textarea id="comment" name="comment" rows="7" cols="100"></textarea><br />
                <button type="submit" style="width: 90px; height: 30px">Comment</button>
            </form>
            <%} %>
            <!--  start paging..................................................... -->
            <% if (Model.Comments.Count > 0)
               { %>
			        <table border="0" cellpadding="0" cellspacing="0" id="paging-table">
			        <tr>
			            <td>
                            <% if (Model.Comments.hasPrevious)
                               { %>
				                    <a href="/Defect/Details/<%: Model.Defect.DefectId %>/1" class="page-far-left"></a>
				                    <a href="/Defect/Details/<%: Model.Defect.DefectId %>/<%: Model.Comments.PageIndex - 1 %>" class="page-left"></a>
                            <% } %>
				            <div class="page-info">Page <strong><%: Model.Comments.PageIndex%></strong> / <%: Model.Comments.TotalPages%></div>
                            <% if (Model.Comments.hasNext)
                               { %>
				                    <a href="/Defect/Details/<%: Model.Defect.DefectId %>/<%: Model.Comments.PageIndex + 1 %>" class="page-right"></a>
				                    <a href="/Defect/Details/<%: Model.Defect.DefectId %>/<%: Model.Comments.TotalPages %>" class="page-far-right"></a>
                            <% } %>
			            </td>
			        </tr>
			        </table>
            <% } %>
			<!--  end paging................ -->
            </fieldset>
		</div>
        <div id="Resolution">
            <div style="width: 100%; height: 500px">
            <% if (Model.Resolution != null)
               {%>
                <div class="contentLeft">Tested By: <strong><%: Model.Resolution.TestedBy%></strong></div>
                <div class="contentRight">Fix Time: <strong><%: Model.Resolution.FixTime%></strong></div>
                <div class="content" style="margin-top: 20px">
                    <fieldset style="width: 100%; min-height: 40px; margin-left: auto; margin-right: auto;"><legend>Solution</legend>
                        <div style="margin: 20px"><%= Model.Resolution.Solution%></div>
                    </fieldset>
                </div>
                <% if(Model.Defect.AssignedMember != null && Model.Defect.AccountAssignedMember.UserName == User.Identity.Name)
                   {%>
                    <div class="content" style="margin-top: 20px"><a href="/Defect/Resolution/<%: Model.Defect.DefectId %>?ReturnUrl=<%= Request.Url.ToString() %>" class="link">Edit</a></div>
                 <%}
               }
               else
               { %>
                No solution yet.<br />
                <% if (Model.Defect.AssignedMember != null && Model.Defect.AccountAssignedMember.UserName == User.Identity.Name)
                   {%>
                    <div style="margin-top: 20px"><a href="/Defect/Resolution/<%: Model.Defect.DefectId %>?ReturnUrl=<%= Request.Url.ToString() %>" class="link">Create</a></div>
                <% }
               } %>
            </div>
        </div>
        <div id="Attachment">
            <div style="width: 95%; height: 500px; position: relative; margin-top: 10px">
            <br /><br />
            <% if (Model.Attachments.Count() > 0)
               {
                   foreach (var item in Model.Attachments.ToList())
                   {%>
                   <div style="margin-top: 20px">
                    <a class="link" href="/Defect/DownloadAttachment?AttachmentId=<%: item.AttachId %>" title="Download"><%: item.FileName%></a> - Upload by: <%: item.Account.UserName%> at <%: String.Format("{0:g}", item.AttachDate)%> - File size: <%: item.Size%>kb
                    <% if (!User.IsInRole("User") || (User.IsInRole("User") && Model.Defect.AccountCreator.UserName == User.Identity.Name) || (User.IsInRole("User") && Model.Defect.AssignedMember != null && Model.Defect.AccountAssignedMember.UserName == User.Identity.Name))
                       {%>  -  <a class="link" href="/Defect/DeleteAttachmentFromDefect/<%: item.AttachId %>" onclick="return confirm('Are you sure to delete this attachment?')" title="Delete attachment">Delete</a><% } %>
                       </div>
                 <%}
               }
               else
               {%><br /><br />
                    No Attachment Available.
             <%}
               if (Model.Attachments.Count() < 5 && (!User.IsInRole("User") || (User.IsInRole("User") && Model.Defect.AccountCreator.UserName == User.Identity.Name) || (User.IsInRole("User") && Model.Defect.AccountAssignedMember.UserName == User.Identity.Name)))
               {%>
                    <% if(Model.Defect.Project.IsActive){ %>
                    <div style="line-height: 25px">
                    <form name="UploadFile" id="UploadFile" action="/Defect/AttachFileToDefect?id=<%: Model.Defect.DefectId %>&pageIndex=<%: Model.Comments.PageIndex %>" method="post" onsubmit="return checkFileSize()" style="position: relative; margin-top: 20px;" enctype="multipart/form-data">
                        Upload File: <input name="FileUpload" type="file" style="width: 300px; height:20px" /><button type="submit" style="width: 60px; height:25px;">Upload</button>
                        <span style="color: Red; font-size: 10px; position: relative; margin-top: 20px" id="FileError"><br />
                        <% if (Session["fileError"] != null) { %>
                              <%: Session["fileError"].ToString() %>                                                      
                       <%      Session["fileError"] = null;
                           } %></span>
                    </form>
                    </div>
                    <%} %>
             <%}%>
             </div>
        </div>
        <div id="History">
            <div style="width: 100%; height: 500px; margin-left: auto; margin-right: auto; display: auto">
                <% 
                   foreach (var item in Model.History.ToList())
                   { %>
                    <div style="margin-top: 20px">
                        <%: item.Content %> at <%: String.Format("{0:g}", item.CreatedTime) %> by <%: item.Account.UserName %>
                     </div>
                <% } %>
            </div>
        </div>
		<!--  end content-table-inner ............................................END  -->
        </div>
		<td id="tbl-border-right"></td>
	</tr>
	<tr>
		<th class="sized bottomleft"></th>
		<td id="tbl-border-bottom">&nbsp;</td>
		<th class="sized bottomright"></th>
	</tr>
	</table>    
</asp:Content>
<asp:Content ContentPlaceHolderID="Fotter" ID="footer" runat="server">
<script type="text/javascript">
    $("#tabs").tabs();
    tinyMCE.init({
        // General options
        mode : "exact",
        elements: "comment",
        theme: "simple",
        plugins: "autolink,lists,pagebreak,style,emotions,insertdatetime,directionality,noneditable,visualchars,wordcount",
        // Example content CSS (should be your site CSS)
        content_css: "css/content.css",

		// Style formats
		style_formats : [
			{title : 'Bold text', inline : 'b'},
			{title : 'Red text', inline : 'span', styles : {color : '#ff0000'}},
			{title : 'Red header', block : 'h1', styles : {color : '#ff0000'}},
			{title : 'Example 1', inline : 'span', classes : 'example1'},
			{title : 'Example 2', inline : 'span', classes : 'example2'},
			{title : 'Table styles'},
			{title : 'Table row 1', selector : 'tr', classes : 'tablerow1'}
		],

        width: "900",
        height: "250"
    });
    function checkFileSize() {
        if (document.UploadFile.FileUpload.value != null) {
            var size;
            if (navigator.appName != "Microsoft Internet Explorer") {
                size = document.UploadFile.FileUpload.files[0].fileSize;
            } else {
                var oas = new ActiveXObject("Scripting.FileSystemObject");
                var a = document.UploadFile.FileUpload.value;
                var file = oas.getFile(a);
                size = file.size;
            }
            if (size > 512000) {
                $("#FileError").html("File size not greater than 500kb");
            } else {
                return true;
            }
        } else {
            $("#FileError").html("Please choose a file.");
        }
        return false;
    }
</script>
</asp:Content>

